<?php
/*
 * 班级表格的自动验证和自动填充
 * 作者:Tobey
 * */
class classModel{
    /**
     * 自动验证
     */
    public $validate = array(
        /**
         * 新增课程的时候进行验证    1  3表示2的时候也会验证
         */
        array("cla_name","require","班级名称不能为空!","regex",1,3),
        array("cla_code","require","班级代码必须有!","regex",1,1),
        array("cla_start",array(10,10),"开始时间要格式要正确!","length",1,3),
        array("cla_end",array(10,10),"结束时间要格式要正确!","length",1,3),
        array("cla_start,cla_end","checkTime","结束时间要大于开始时间而且开启使用要小于1年!","callback",1,3),
        array("is_auto",array(0,1),"是否启用有误!","in",1,3), 
        array("is_filed",array(0,1),"归档处理只有归档或不归档!","in",1,2),
        );

    /*
     * 自动填充
     * */
    public $auto = array(
        /*
         * 1表示新增的时候进行自动填充
         * */
        array("cla_stu_num","fill",0,1),            
        array("is_filed","fill",0,1),  
        );

    /**
     * 检查时间是否符合规范
     */
    public function checkTime($time){
        $start = strtotime($time["cla_start"]);
        $end = strtotime($time["cla_end"]);
        if($end<$start || $end-$start>31536000){
            return false;
        }
        return true;
    }

}